﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EMANIFEST.Dtos;

namespace TestSaveRecord
{
    /// <summary>
    /// Summary description for TestGoodDeclaration
    /// </summary>
    [TestClass]
    public class TestGoodDeclarationRecord
    {
        eManifestService.EmanifestServiceClient client = new eManifestService.EmanifestServiceClient();
        public TestGoodDeclarationRecord()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestGoodDeclaration()
        {
            try
            {
                GoodDeclarationDto good = new GoodDeclarationDto();
                good.GoodDeclarationId = new Guid("9998430B-E7B8-43A7-B46F-E89C25F165E8");
                good.DocumentId = new Guid("DAB27624-2270-4C40-A977-8856C4A8388A");
                good.Decription = "Demo update";
                good.NumberOfPackage = new Nullable<Decimal>(11);
                good.CreaterId = new Guid("93ec220c-5b57-4dac-88aa-9a314e1a7424");
                good.CreatedDate = DateTime.Now;
                good.IsTemp = false;

                
                client.SaveGoodDeclarationRecord(good);

                // kiem tra exists
                GoodDeclarationDto dgdto = client.GetGoodDeclarationById(good.GoodDeclarationId);
                if (dgdto != null)
                    Console.WriteLine("cap nhat thanh cong");
                else
                    Console.WriteLine("cap nhat that bai");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }

        [TestMethod]
        public void DeleteGoodDeclaration()
        {
            try
            {
                ResponseDto res = client.DeleteGoodDeclaration(new Guid("9998430B-E7B8-43A7-B46F-E89C25F165E8"));
                Console.WriteLine(res.IsSuccess);
                GoodDeclarationDto gddto = client.GetGoodDeclarationById(new Guid("9998430B-E7B8-43A7-B46F-E89C25F165E8"));
                if (gddto == null)
                    Console.WriteLine("Delete thanh cong");
                else
                    Console.WriteLine("Delete that bai");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }

        [TestMethod]
        public void TestGoodItem()
        {
            try
            {
                GoodItemDto dItemdto = new GoodItemDto();
                dItemdto.GoodItemId = new Guid("FF210E8F-59CD-491A-ACD9-F390FBCECBFF");
                dItemdto.MasterBillNo = "No 1";
                dItemdto.Consigner = "tien tan";
                dItemdto.Consignee = "tan tien nguyen update";
                dItemdto.NotificatedParty = "Notificated 1";
                dItemdto.ContNumber = "Cont 1";
                dItemdto.ContSealNumber = "seal 1";
                dItemdto.GoodDescription = "Description";
                dItemdto.NetWeight = 10;
                dItemdto.GrossWeight = 100;
                dItemdto.Demension = 100;
                dItemdto.RefNumber = "Ref num 1";
                dItemdto.Ajustment = "Ajustment 1";
                dItemdto.GoodDeclarationId = new Guid("9998430B-E7B8-43A7-B46F-E89C25F165E8");
                dItemdto.ItemCodeId = new Guid("00000000-0000-0000-0000-000000000000");
                // save
                client.SaveGoodItemRecord(dItemdto);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }


        [TestMethod]
        public void DeleteGOodItem()
        {
            try
            {
                ResponseDto res = client.DeleteGoodItem(new Guid("FF210E8F-59CD-491A-ACD9-F390FBCECBFF"));
                Console.WriteLine(res.IsSuccess);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }


        
    }
}
